home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / CON-03A.ZIP / COMMS.PAS < prev    next >
Pascal/Delphi Source File  |  1995-04-17  |  4KB  |  210 lines

  1. unit comms;
  2.  
  3. interface
  4.  
  5. var
  6.  
  7. comport,modemspeed : integer;
  8. secret, auto_det : boolean;
  9.  
  10. procedure  sendln(stri : string);
  11. procedure  sendch(cha : char);
  12. function   getch                      : char;
  13. procedure  init_comms;
  14. function   carrier                    : boolean;
  15. procedure  sc(cha : char);
  16. procedure  send(stri : string);
  17. function   num(numb : longint)        : string;
  18. function   unnum(string_num : string) : integer;
  19. function   wfk                        : char;
  20. function   getstring                  : string;
  21. procedure  clearscreen;
  22. procedure  modem_cmd(stri : string);
  23. procedure  xy(x,y : integer);
  24.  
  25. implementation
  26.  
  27. uses crt, ansi_drv;
  28.  
  29.  
  30. function char_avail : boolean;
  31. var
  32.    status : byte;
  33. begin
  34.    asm
  35.       mov  ah,03h
  36.       mov  dx,comport
  37.       int  14h
  38.       mov  status, ah
  39.    end;
  40.    char_avail:=(status and 1) = 1;
  41. end;
  42.  
  43. procedure sendch(cha : char);
  44. var status : byte;
  45.     tosend : byte;
  46. begin
  47.   status:=128;
  48.   tosend:=ord(cha);
  49.   repeat
  50.     asm
  51.       mov ah,01
  52.       mov dx,comport
  53.       mov al,tosend
  54.       int 14h
  55.       mov status,ah
  56.     end
  57.   until (status and 128) = 0;
  58. end;
  59.  
  60.  
  61. function getch : char;
  62. var status,cha : byte;
  63. begin
  64.     status:=128;
  65.     if char_avail then begin
  66.       asm
  67.         mov ah,02
  68.         mov dx,comport
  69.         int 14h
  70.         mov cha,al
  71.         mov status,ah
  72.       end;
  73.     end;
  74.     if (status and 128) = 128 then getch:=chr(255) else getch:=chr(cha);
  75. end;
  76.  
  77.  
  78. procedure init_comms;
  79. var speed : byte;
  80. begin
  81. {  writeln('Initialising communications port!');
  82.   case modemspeed of
  83.     19200 : speed:=8;
  84.      9600 : speed:=7;
  85.      4800 : speed:=6;
  86.      2400 : speed:=5;
  87.      1200 : speed:=4;
  88.   end;
  89.   asm
  90.     mov ah,04
  91.     mov al,00
  92.     mov bx,00
  93.     mov ch,03
  94.     mov cl,speed
  95.     mov dx,comport
  96.     int 14h
  97.   end;
  98.   sound(1000);
  99.   delay(50);
  100.   sound(700);
  101.   delay(50);
  102.   nosound; }
  103. end;
  104.  
  105. function carrier : boolean;
  106. var status : byte;
  107. begin
  108.   asm
  109.     mov   ah,03
  110.     mov   dx,comport
  111.     int   $14
  112.     mov   status,al
  113.   end;
  114.   carrier := status and 32 = 32;
  115. end;
  116.  
  117. procedure modem_cmd(stri : string);
  118. var aa : integer;
  119. begin
  120.   if not carrier then begin
  121.       sound(1500);
  122.       delay(20);
  123.       nosound;
  124.  {     sendch(#13);
  125.       for aa:=1 to length(stri) do sendch(stri[aa]);
  126.       sendch(#13); }
  127.   end;
  128. end;
  129.  
  130.  
  131. procedure sc(cha : char);
  132. begin
  133.   if carrier and not secret then sendch(cha);
  134.   if secret and carrier then sendch('■');
  135.   ansi_write(cha);
  136. end;
  137.  
  138.  
  139. procedure send(stri : string);
  140. var aa : integer;
  141. begin
  142.   for aa:=1 to length(stri) do sc(stri[aa]);
  143. end;
  144.  
  145.  
  146. procedure sendln(stri : string);
  147. var aa : integer;
  148. begin
  149.   for aa:=1 to length(stri) do sc(stri[aa]);
  150.   sc(chr(13));
  151.   sc(chr(10));
  152. end;
  153.  
  154.  
  155. function num(numb : longint) : string;
  156. var s : string;
  157. begin
  158.   str(numb, s);
  159.   num:=s;
  160. end;
  161.  
  162.  
  163. function unnum(string_num : string) : integer;
  164. var num,foo : integer;
  165. begin
  166.     val(string_num,num,foo);
  167.     unnum:=num;
  168. end;
  169.  
  170.  
  171. function wfk : char;
  172. var ch : char;
  173. begin
  174.   ch:=#255;
  175.   repeat
  176.     if keypressed then ch:=readkey else
  177.     if carrier then ch:=getch;
  178.   until ch<>chr(255);
  179.   sc(ch);
  180.   wfk:=ch;
  181. end;
  182.  
  183.  
  184. function getstring : string;
  185. var count : integer;
  186.     ch : char;
  187. begin
  188.   count:=0;
  189.   repeat
  190.     ch:=wfk;
  191.     if (ch<>#13) and (ch<>#8) then begin
  192.       inc(count);
  193.       getstring[count]:=ch;
  194.     end else if ch=#8 then dec(count);
  195.   until ch=#13;
  196.   getstring[0]:=chr(count);
  197. end;
  198.  
  199. procedure xy(x,y : integer);
  200. begin
  201.   send(#27+'['+chr(x+ord('0'))+';'+chr(y+ord('0'))+'F');
  202. end;
  203.  
  204. procedure clearscreen;
  205. begin
  206.   send(#27+'[2J');
  207.   clrscr;
  208. end;
  209.  
  210. end. {unit ends}